package com.herench.bs.handler;

import com.herench.bs.agent.IPersonAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * Created by ThinkPad on 2017/8/27.
 */
@Component
@Handler(code="100206",name="新增就诊卡")
public class TreatmentCardHandler extends AbstractMessageHandler {

    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = null;

        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        String idCard = requestMessage.getArgsPropertyStringValue("user");
        String cardType = requestMessage.getArgsPropertyStringValue("cardType");
        String cardNumber = requestMessage.getArgsPropertyStringValue("cardNumber");
        String defaultFlag = requestMessage.getArgsPropertyStringValue("defaultFlag");
        String selfFlag = requestMessage.getArgsPropertyStringValue("selfFlag");
        String appImei = requestMessage.getArgsPropertyStringValue("appImei");

        Assert.isTrue(StringUtils.hasLength(channelCode), "sysCode 不能为空.");
        Assert.isTrue(StringUtils.hasLength(idCard), "user 不能为空.");
        Assert.isTrue(StringUtils.hasLength(cardType), "cardType 不能为空.");
        Assert.isTrue(StringUtils.hasLength(cardNumber), "cardNumber 不能为空.");
        Assert.isTrue(StringUtils.hasLength(defaultFlag), "defaultFlag 不能为空.");

        IPersonAgent personAgent = getCleverClinicContext().getApplicationContext().getBean(IPersonAgent.class);
        Map<String, Object> res = personAgent.addTreatmentCard(channelCode, idCard, cardType, cardNumber, defaultFlag);
        responseMessage = new ResponseMessage(requestMessage.getId());
        responseMessage.setData(res);
        responseMessage.setDataAttribute("cardNumber", cardNumber);
        responseMessage.setDataAttribute("cardType", cardType);
        /**
         * 此处先返回卡类型为医保卡
         */
        responseMessage.setDataAttribute("cardTypeName", "医保卡");
        responseMessage.setDataAttribute("defaultFlag", defaultFlag);
        responseMessage.setDataAttribute("idCard", idCard);
        getPropertiesFromInvokerResultMap(responseMessage,res);
        return responseMessage;
    }
}
